package core

class BuildingController {

    def index() {
		def max = params.long('max')?:10
		
			   def start = params.long('start')?:1
		
			   render(view:'index', model : [building: Building.list(max: max, offset:start)])
	}
	def create() {
	
}
	def show() {
		
			   [building:Building.get(params.long('id'))]
		
		   }
	
	def save() {
		
			   def building = new Building(params)
		
			   if (building.save()) {
		
				   flash.notice = "Building: ${building.name} was saved"
		
				   redirect(action: 'index')
		
			   }
		
			   else {
		
				   flash.error = "Building: ${building.name} failed to be saved"
		
				   render(view:'create', model:[building: Building])
		
			   }
		
		
		   }
	
	def update() {
		
			   def building =  Building.get(params.long('id'))
		
			   building.properties = params
		
			   if(building.save()) {
		
				   flash.notice = "Building: ${building.name} was updated"
		
				   redirect action:'index'
		
			   }
		
			   else {
		
				   flash.error = "Building:  failed to be update"
		
				   render(view:'edit', model:[building: Building])
		
			   }
		
		   }
	
	def delete(){
		
	   
		
			   def Build = Building.get(params.id)
		
			   Build.delete()
		
			   redirect(action:"index")
		
		   }
		
	   
		
		   def edit(){
		
	   
		
			   [building: Building.get(params.long('id'))]
		
	   
		
	   
		
		   }
		
	   }
	   
	

